package org.example.myleet.p796;

public class Solution {
    public boolean rotateString(String s, String goal) {
        if (s.length() != goal.length()) {
            return false;
        }
        char[] sArr = s.toCharArray();
        char[] goalArr = goal.toCharArray();
        int i = 0, j = 0, end = 2 * sArr.length;
        while (i < end) {
            boolean moved = false;
            while (j < goalArr.length && sArr[i % sArr.length] == goalArr[j]) {
                moved = true;
                ++i;
                ++j;
            }
            if (j == goalArr.length) {
                return true;
            }
            j = 0;
            if (!moved) {
                ++i;
            }
        }
        return false;
    }
}
